package main

import (
	pb "GoStart/z_demo/grpc-gin-validate/proto" // 引入生成的 proto 文件
	"github.com/gin-gonic/gin"
	"net/http"
)

type validator interface {
	Validate() error
}

func Validator(req interface{}) (err error) {
	if v, ok := req.(validator); ok {
		if err := v.Validate(); err != nil {
			return err
		}
	}
	return nil
}

func main() {
	r := gin.Default()
	r.POST("/create_user", func(c *gin.Context) {
		var req pb.UserRequest
		if err := c.ShouldBind(&req); err != nil {
			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
			return
		}
		if err := req.Validate(); err != nil {
			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
			return
		}
		// TODO: 处理请求
	})
	r.Run()
}
